package com.echo.code.thread.mode.eda;

import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * TestCase
 */
public class TestCase {

  public static void main(String[] args) {
    EventDispatcher dispatcher = new EventDispatcher();
    dispatcher.registerChannel(TestCase.SimpleEvent.class, new SimpleEventHandler());
    dispatcher.dispatch(new TestCase.SimpleEvent());

    try {
      TimeUnit.SECONDS.sleep(5);
    } catch (InterruptedException e) {
    }
    dispatcher.shutdown();
  }

  public static class SimpleEvent extends Event {

  }

  public static class SimpleEventHandler extends EventHandler {

    public SimpleEventHandler()  {
      super(Executors.newSingleThreadExecutor());
    }

    @Override
    protected void handle(Event event) {
      System.out.println(event.getClass().getName());
    }
  }
}